layui.use(['form', 'laydate','layer','table'], function(){
    var form = layui.form
        ,laydate = layui.laydate
        ,layer = layui.layer
        ,table = layui.table;
    var $ = layui.$;
    var $addform = $('.j-add-form')
    $('.j-blog-add').click(function () {
        layer.open({
            type: 1,
            title: '',
            shade : 0.5,
            resize: false,
            area : ['400px','310px'],
            content: $addform,
            area: '420px', 
            end: function () {
                $addform.find("input").val("");
            }
        });
    })
    table.render({
        elem: '#table'
        ,url:'/test/table/demo1.json'
        ,title: '用户数据表'
        ,cols: [[
            ,{field:'id', title:'序号', width:80, fixed: 'left'}
            ,{field:'className', title:'分类名称'}
            ,{field:'articleNums', title:'文章数', width:120}
            ,{fixed: 'right', title:'操作', toolbar: '#barOperation', width:150}
        ]]
        ,page: false
    });
    //监听行工具事件，
    table.on('tool(table)', function(obj){
        var data = obj.data;
        //console.log(obj)
        if(obj.event === 'del'){
            layer.confirm('真的删除行么', function(index){
                obj.del();
                layer.close(index);
            });
        } else if(obj.event === 'edit'){
            layer.prompt({
                formType: 2
                ,value: data.className
            }, function(value, index){
                obj.update({
                    className: value
                });
                layer.close(index);
            });
        }
    });
})